<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>服务器实现数字转换中文</title>
<script type="text/javascript">
	//获得xmlHttp对象
	var xmlHttp;
	try {
		//非IE、新IE
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		//IE6
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			//IE5.5
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("不支持Ajax");
			}
		}
	}

	function doGet(num) {
		//1、准备请求资源
		xmlHttp.open("get", "Servlet2?num=" + num);

		//2、准备（设置）回调函数，当响应结果回来，响应函数
		xmlHttp.onreadystatechange = getBack;

		//3、发送请求
		xmlHttp.send();
	}

	function getBack() {
		if (xmlHttp.readyState == 4) {
			document.getElementById("img").style.display = "none";
			if (xmlHttp.status == 200) {
				document.getElementById("get").innerHTML = xmlHttp.responseText;
			} else {
				document.getElementById("get").innerHTML = "-->出错<--";
			}
		} else {
			document.getElementById("img").style.display = "block";
		}
	}

	function doPost(num) {
		xmlHttp.open("post", "Servlet2");
		xmlHttp.setRequestHeader("Content-Type",
				"application/x-www-form-urlencoded");
		xmlHttp.onreadystatechange = postBack;
		xmlHttp.send("num=" + num);

	}

	function postBack() {
		if (xmlHttp.readyState == 4) {

			document.getElementById("post").innerHTML = xmlHttp.responseText;
		}
	}
</script>

</head>
<body>
	<center>
		get方式：<input type="text" onkeyup="doGet(this.value)"> <br />
		<div id="get" style="width:200px"></div>
		<img alt="loading" src="loading.gif" id="img" style="display: none;">
		<br /> post方式:<input type="text" onkeyup="doPost(this.value)">
		<br />
		<div id="post" style="width:200px"></div>
	</center>
</body>
</html>